package jack.code.hnzb.service;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;

/**
 * Created by LiJiakui on 17/5/9.
 */
public class SendMessage {

    public static String WEBHOOK_TOKEN = "https://oapi.dingtalk.com/robot/send?access_token=cbd96536c30ec17e667f553132429fb8b04e38571f51ca1cca672a1d5b4a9872";

    public static String SEACH_TOKEN_2 = "https://oapi.dingtalk.com/robot/send?access_token=ce76834dba2fad02152d02ea0844d11d914bd9a128954b607812674bce1ed073";



    public static HttpResponse sendMsg(String url,String msg){
        try {
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost(url);
            httppost.addHeader("Content-Type", "application/json; charset=utf-8");
            String textMsg = "{ \"msgtype\": \"text\", \"text\": {\"content\": \""+msg+"\"}}";
            StringEntity se = new StringEntity(textMsg, "utf-8");
            httppost.setEntity(se);
            HttpResponse response = httpclient.execute(httppost);
            return response;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 中环相关信息发送
     * @param msg
     * @return
     */
    public static HttpResponse sendMsg1(String msg){
        return sendMsg(WEBHOOK_TOKEN,msg);
    }

    /**
     * 其他信息发送
     * @param msg
     * @return
     */
    public static HttpResponse sendMsg2(String msg){
        return sendMsg(SEACH_TOKEN_2,msg);
    }
}
